/*
 * Copyright (c) 2017年11月07日  by XuanWu Wireless Technology Co., Ltd 
 *             All rights reserved  
 */
package com.zml.second.example2;

import java.util.Observable;
import java.util.Observer;

/**
 * @author <a href="mailto:zhaominglin@wxchina.com">minglin.Zhao</a>
 * @Description
 * @Date 2017/11/7
 * @Version 1.0.0
 */
public class CurrentConditionDisplay implements Observer {
    private Observable observable;
    private float temperature;
    private float humidity;

    public CurrentConditionDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData){
            WeatherData weatherData = (WeatherData)o;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display();
        }
    }

    public void display() {
        System.out.println("CurrentConditionDisplay{" +
                "temperature=" + temperature +
                ", humidity=" + humidity +
                '}');
    }
}
